<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('业务时间')">
              <j-date
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('开始时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('会员信息')">
              <a-input :placeholder="$t('请输入手机号/卡号/姓名/邮箱')" v-model="queryParam.keyword"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('设备名称(编码)')">
                <a-select show-search :filter-option="false" @search="handleSearch" v-model="queryParam.deviceId">
                  <a-select-option :value="item.id" :key="index" v-for="(item, index) in deviceList">
                    <span>{{ item.name }}</span>
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('业务渠道')">
                <j-dict-select-tag
                  :placeholder="$t('请选择业务渠道')"
                  v-model="queryParam.deviceType"
                  dictCode="bis_device_info.type"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('订单号')">
                <a-input :placeholder="$t('请输入订单号')" v-model="queryParam.orderId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('业务类型')">
                <a-input
                  read-only
                  :placeholder="$t('请选择业务类型')"
                  v-model="queryParam.typeNames"
                  @click="selectType">
                </a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('机号')">
                <a-input :placeholder="$t('请输入机号')" v-model="queryParam.machineNo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('机台名称')">
                <a-select show-search :filter-option="false" @search="gameSearch" v-model="queryParam.gameId">
                  <a-select-option :value="item.id" :key="index" v-for="(item, index) in gameList">
                    <span>{{ item.name }}</span>
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('商户信息')">
                <a-input :placeholder="$t('请输入商户编码/名称')" v-model="queryParam.supplierInfo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('操作员')">
                <a-select s v-model="queryParam.createBy">
                  <a-select-option :value="item.id" :key="index" v-for="(item, index) in userList">{{
                    item.realname
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="!tenantid">
              <a-form-item :label="$t('门店')">
                <a-select v-model="queryParam.shopCode">
                  <a-select-option v-for="(item, i) in shops" :key="i" :value="item.value"
                    >{{ item.title }}<span v-if="item.value != ''">（{{ item.value }}）</span></a-select-option
                  >
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('备注')">
                <j-input :placeholder="$t('请输入备注')" v-model="queryParam.comment"></j-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
              }}</a-button>
              <a-button
              v-has="'BisMemberAccountChangeController:export'"
                type="primary"
                icon="download"
                :loading="exloading"
                @click="handleExportXls($t('会员业务明细'))"
                style="margin-left: 8px"
                >{{ $t('导出') }}</a-button
              >
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
              <a-popover :title="$t('自定义列')" trigger="click" placement="leftBottom">
                <template slot="content">
                  <a-checkbox-group
                    @change="onColSettingsChange"
                    v-model="settingColumns"
                    :defaultValue="settingColumns"
                  >
                    <a-row style="width: 400px">
                      <template v-for="(item, i) in defColumns">
                        <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                          <a-col :span="12" :key="i"
                            ><a-checkbox :value="item.dataIndex"
                              ><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox
                          ></a-col>
                        </template>
                      </template>
                    </a-row>
                  </a-checkbox-group>
                </template>
                <a-button style="margin-left: 8px" type="setting">{{ $t('设置列') }}</a-button>
              </a-popover>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true, y: tableHeight }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :customHeaderRow="customHeaderRow"
        :customRow="customRow"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无图片') }}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无文件') }}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">{{
            $t('下载')
          }}</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a-dropdown>
            <a class="ant-dropdown-link">
              {{ $t('更多') }}
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click.stop="handleDetail(record)">{{ $t('详情') }}</a>
              </a-menu-item>
              <a-menu-item @click="handleParentClick">
                <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
                  <a>{{ $t('删除') }}</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <span s slot="createTime" slot-scope="text, record">
          <a v-if="record.orderId" @click.stop="showOrder(record)">{{ text }}</a>
          <a v-else-if="record.typeId == '8'" @click.stop="showDtl(record)">{{ text }}</a>
          <span v-else>{{ text }}</span>
        </span>
        <template slot="footer">
          <div style="font-weight: bold">
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('交易币值') }}：</span>
            <span>{{ totalInfo && (totalInfo.realCoinValue||totalInfo.presentCoinValue) ? (totalInfo.realCoinValue + totalInfo.presentCoinValue).toFixed(2):'0.00' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('交易积分') }}：</span>
            <span>{{ totalInfo && totalInfo.integralValue ? totalInfo.integralValue.toFixed(0):'0' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('交易彩票') }}：</span>
            <span>{{ totalInfo && totalInfo.lotteryValue ? totalInfo.lotteryValue.toFixed(0):'0' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('交易A票') }}：</span>
            <span>{{ totalInfo && totalInfo.alotteryValue ? totalInfo.alotteryValue.toFixed(0):'0' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('交易A币') }}：</span>
            <span>{{ totalInfo && totalInfo.pointsValue ? totalInfo.pointsValue.toFixed(0):'0' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('交易限时币') }}：</span>
            <span>{{ totalInfo && totalInfo.limitCoinValue ? totalInfo.limitCoinValue.toFixed(0):'0' }}</span>
            <span style="margin-left: 15px; margin-right: 5px">{{ $t('交易成长值') }}：</span>
            <span>{{ totalInfo && totalInfo.growthValue ? totalInfo.growthValue.toFixed(0):'0' }}</span>
          </div>
        </template>
      </a-table>
    </div>

    <type-name-modal ref="typeNameForm"></type-name-modal>
    <member-sharedtl-modal ref="shareModal" />
    <business-type-modal ref="typeForm" @ok="selectTypeOk"></business-type-modal>
  </a-card>
</template>

<script>
import Vue from 'vue'
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { getAction, downFile } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import TypeNameModal from './modules/TypeNameModal'
import MemberSharedtlModal from './modules/MemberSharedtlModal'
import BusinessTypeModal from './modules/BusinessTypeModal'

export default {
  name: 'MemberBusinessList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    TypeNameModal,
    JMultiSelectTag,
    MemberSharedtlModal,
    BusinessTypeModal
  },
  data() {
    return {
      description: '会员业务明细管理页面',
      moment,
      tenantid: Vue.ls.get('TENANT_ID'),
      //列设置
      settingColumns: [],
      // 表头
      columns: [],
      // 表头
      defColumns: [
        {
          title: this.$t('业务时间'),
          align: 'center',
          dataIndex: 'createTime',
          fixed: 'left',
          width: 90,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          scopedSlots: { customRender: 'createTime' },
        },
        {
          title: this.$t('机号'),
          align: 'center',
          dataIndex: 'machineNo',
          fixed: 'left',
          width: 76,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customHeaderCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('业务类型'),
          align: 'center',
          dataIndex: 'typeId_dictText',
          width: 90,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('交易前类型'),
          align: 'center',
          dataIndex: 'memberType_dictText',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('交易后类型'),
          align: 'center',
          dataIndex: 'memberTypeAfter_dictText',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'phone',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'chipNo',
          width: 96,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('邮箱'),
          align: 'center',
          dataIndex: 'email',
          width: 160,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('会员姓名'),
          align: 'center',
          dataIndex: 'name',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('交易前币'),
          align: 'right',
          dataIndex: 'realCoinBefore',
          customRender: function (r, record) {
            return (record.realCoinBefore + record.presentCoinBefore).toFixed(2)
          },
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('交易币'),
          align: 'right',
          dataIndex: 'realCoinValue',
          customRender: function (r, record) {
            return (record.realCoinValue + record.presentCoinValue).toFixed(2)
          },
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('交易后币'),
          align: 'right',
          dataIndex: 'realCoinAfter',
          customRender: function (r, record) {
            return (record.realCoinAfter + record.presentCoinAfter).toFixed(2)
          },
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('交易前积分'),
          align: 'right',
          dataIndex: 'integralBefore',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易积分'),
          align: 'right ',
          dataIndex: 'integralValue',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易后积分'),
          align: 'right',
          dataIndex: 'integralAfter',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易前彩票'),
          align: 'right',
          dataIndex: 'lotteryBefore',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易彩票'),
          align: 'right',
          dataIndex: 'lotteryValue',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易后彩票'),
          align: 'right',
          dataIndex: 'lotteryAfter',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易前A票'),
          align: 'right',
          dataIndex: 'alotteryBefore',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易A票'),
          align: 'right',
          dataIndex: 'alotteryValue',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易后A票'),
          align: 'right',
          dataIndex: 'alotteryAfter',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易前A币'),
          align: 'right',
          dataIndex: 'pointsBefore',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易A币'),
          align: 'right',
          dataIndex: 'pointsValue',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易后A币'),
          align: 'right',
          dataIndex: 'pointsAfter',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易前限时币'),
          align: 'right',
          dataIndex: 'limitCoinBefore',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易限时币'),
          align: 'right',
          dataIndex: 'limitCoinValue',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易后限时币'),
          align: 'right',
          dataIndex: 'limitCoinAfter',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易前成长值'),
          align: 'right',
          dataIndex: 'growthBefore',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易成长值'),
          align: 'right',
          dataIndex: 'growthValue',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易后成长值'),
          align: 'right',
          dataIndex: 'growthAfter',
          width: 110,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
          customRender: (text, r) => {
            return text.toFixed(0);
          }
        },
        {
          title: this.$t('交易前有效期'),
          align: 'center',
          dataIndex: 'validityEnd',
          customRender: (t) => {
            if (t) {
              return moment(t).format('YYYY-MM-DD')
            } else {
              return ''
            }
          },
          width: 106,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('交易后有效期'),
          align: 'center',
          dataIndex: 'validityEndAfter',
          customRender: (t) => {
            if (t) {
              return moment(t).format('YYYY-MM-DD')
            } else {
              return ''
            }
          },
          width: 106,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('商户编码'),
          align: 'center',
          dataIndex: 'bisGoodsSupplierList[0].code',
          width: 120,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('商户名称'),
          align: 'center',
          dataIndex: 'bisGoodsSupplierList[0].name',
          width: 120,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('设备编码'),
          align: 'center',
          dataIndex: 'deviceId',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('设备名称'),
          align: 'center',
          dataIndex: 'deviceId_dictText',
          width: 120,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('机台名称'),
          align: 'center',
          dataIndex: 'gameId_dictText',
          width: 120,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('业务渠道'),
          align: 'center',
          dataIndex: 'deviceType_dictText',
          width: 90,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'createBy',
          width: 90,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        {
          title: this.$t('订单号'),
          align: 'center',
          dataIndex: 'orderId',
          width: 170,
        },
        {
          title: this.$t('备注'),
          align: 'center',
          dataIndex: 'comment',
          width: 200,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
      ],
      url: {
        list: '/member/bisMemberAccountChange/list',
        exportXlsUrl: '/member/bisMemberAccountChange/exportXls',
        totalUrl: '/member/bisMemberAccountChange/total',
      },
      dictOptions: {},
      queryParam: {
        createTime_begin: moment().format('YYYY-MM-DD 00:00:00'),
        createTime_end: moment().format('YYYY-MM-DD 23:59:59'),
        deviceId: '',
        shopCode: '',
        gameId: '',
        createBy: ''
      },
      deviceList: [],
      gameList: [],
      userList: [],
      shops: [],
      isfooter: true,
      isCustom: true,
      isHideData: false,
      hideCond: 3,
      thRows: 1,
    }
  },
  created() {
    if (!this.tenantid) {
      let dtl = {
          title: this.$t('门店编码'),
          align: 'center',
          dataIndex: 'shopCode',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        dtl1 = {
          title: this.$t('门店名称'),
          align: 'center',
          dataIndex: 'shopCode_dictText',
          width: 140,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        }
      this.defColumns.push(dtl1)
      this.defColumns.push(dtl)
    }
    this.initColumns()
  },
  mounted() {
    let that = this
    document.onkeydown = function (e) {
      let key = window.event.keyCode
      if (key == 75 && event.ctrlKey) {
        window.event.preventDefault()
        that.isHideData = false
        that.queryParam.dataType = 0
        that.searchQuery()
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    selectType(){
      if(this.queryParam.typeNames){
        this.$refs.typeForm.edit(this.queryParam.typeIds)
      }else{
        this.$refs.typeForm.edit()
      }
    },
    selectTypeOk(selectTypeList){
      this.$set(this.queryParam, "typeIds", selectTypeList.map(item => item.value).join(","))
      this.$set(this.queryParam, "typeNames", selectTypeList.map(item => item.label).join(","))
      this.searchQuery()
    },
    showOrder(record) {
      let order = {}
      getAction('/order/bisOrder/list', { id: record.orderId }).then((res) => {
        if (res.success) {
          order = res.result.records[0]
          this.$refs.typeNameForm.edit(order)
        }
      })
    },
    showDtl(record){
      this.$refs.shareModal.show(record)
    },
    initDictConfig() {
      this.customInit()
      initDictOptions('bis_shop,name,code').then((res) => {
        if (res.success) {
          this.shops = res.result
          this.shops.unshift({ value: '', title: this.$t('全部') })
        }
      })
      getAction('/sys/user/list').then((res) => {
        if (res.success) {
          this.userList = res.result.records
          this.userList.forEach((col) => {
            col.id = col.realname
          })
          this.userList.unshift({ id: '', realname: this.$t('全部') })
        }
      })
    },
    customInit() {
      this.handleSearch('')
      this.gameSearch('')
      this.isHideData = true
      this.queryParam.dataType = 2
      this.loadData(1)
    },
    handleSearch(value) {
      let query = {}
      if (value) {
        query.deviceInfo = value
      }
      getAction('/device/bisDeviceInfo/list', query).then((res) => {
        if (res.success) {
          this.deviceList = res.result.records
          this.deviceList.unshift({ id: '', name: this.$t('全部') })
        }
      })
    },
    gameSearch(value) {
      let query = {}
      if (value) {
        query.gameInfo = value
      }
      getAction('/game/bisGame/nameList', query).then((res) => {
        if (res.success) {
          this.gameList = res.result.records
          this.gameList.unshift({ id: '', name: this.$t('全部') })
        }
      })
    },
    searchReset() {
      this.queryParam = {
        createTime_begin: moment().format('YYYY-MM-DD 00:00:00'),
        createTime_end: moment().format('YYYY-MM-DD 23:59:59'),
        phone: '',
        chipNo: '',
        name: '',
        deviceId: '',
        shopCode: '',
        gameId: '',
        createBy: '',
        keyword: ''
      }
      this.selectedRowIndex = []
      this.customInit()
    },
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ':colsettings'
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
      this.settingColumns = checkedValues
      const cols = this.defColumns.filter((item) => {
        if (item.key == 'rowIndex' || item.dataIndex == 'action') {
          return true
        }
        if (this.settingColumns.includes(item.dataIndex)) {
          return true
        }
        return false
      })
      this.columns = cols
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');
      var key = this.$route.name + ':colsettings'
      let colSettings = Vue.ls.get(key)
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = []
        this.defColumns.forEach(function (item, i, array) {
          allSettingColumns.push(item.dataIndex)
        })
        this.settingColumns = allSettingColumns
        this.columns = this.defColumns
      } else {
        this.settingColumns = colSettings
        const cols = this.defColumns.filter((item) => {
          if (item.key == 'rowIndex' || item.dataIndex == 'action') {
            return true
          }
          if (colSettings.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols
      }
    },
    handleExportXls(fileName) {
      this.exloading = true
      if(this.ipagination.total>20000){
        this.$message.warning(this.$t('为了保证服务器的稳定运行，单次导出记录不允许超过2万，请修改查询条件后重新导出。'))
        this.exloading = false
        return
      }
      if (!fileName || typeof fileName != "string") {
        fileName = this.$t('导出文件')
      }
      let param = this.getQueryParams();
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(",")
      }
      if (this.isNoPageTotal) {
        param.pageSize = 99999999;
      }
      param.hideColumns = this.getColumnField('columns','defColumns')
      console.log("导出参数", param)
      downFile(this.url.exportXlsUrl, param).then((data) => {
        if (!data) {
          this.$message.warning(this.$t('文件下载失败'))
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link); //下载完成移除元素
          window.URL.revokeObjectURL(url); //释放掉blob对象
        }
      }).finally(() => {
        this.exloading = false
      })
    },
    getColumnField(key,dkey){
      let arr=[],str=''
      this[dkey].forEach(dk=>{
        let x= this[key].findIndex(k=>{
          return dk.dataIndex==k.dataIndex
        })
        if(x==-1){
          arr.push(dk)
        }
      })
      str=arr.map(a=>{return a.dataIndex}).join(',')
      return str
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
<style>
.cus-select-multi .ant-select-selection--multiple {
  max-height: 32px;
  overflow: auto;
}
</style>